<script>
    $(function() {
        var tabs = $("#tabs").tabs();
        tabs.find(".ui-tabs-nav").sortable({
            axis: "x",
            stop: function() {
                tabs.tabs("refresh");
            }
        });
    });

    $(document).ready(function(){
        // date picker
        $(".tanggal").datepicker({
            yearRange: '-1:+1',
            target: 'tanggal',
            changeMonth: true,
            changeYear: true,
            showOn: 'both',
            buttonImage: '{$BASEURL}/resource/doc/images/icon/calendar.gif',
            buttonImageOnly: true,
            dateFormat: 'yy-mm-dd'
        });
        
        $("select[name='gpbarang_cd']").select2();
        $("select[name='kategoribarang_cd']").select2();
        $("select[name='jenisbarang_cd']").select2();
        $("select[name='merk_cd']").select2();
        $("select[name='barang_kondisi']").select2();
        $("select[name='barang_status']").select2();
        $("select[name='lokasi_cd']").select2();
        $("select[name='ruang_cd']").select2();
        $("select[name='vendor_cd']").select2();
        {if (!empty($result.jenisbarang_cd))}
        // get jenis barang
        getJenisBarang($("#kategoribarang_cd").val(),{$result.jenisbarang_cd});
        function getJenisBarang(kategoribarang,jenisbarang){
	    $.ajax({
                type: 'POST',
                data: 'kategoribarang=' + kategoribarang +'&jenisbarang='+ jenisbarang,
                url: '{$config->site_url("inventarisasi/pengadaan/cari_jenis_barang")}',
                success: function(result) {
                    $('#jenisbarang_cd').html(result);
                    $('#jenisbarang_cd').trigger("change");
                }
            });
	}
        {/if}
        
        {if (!empty($result.merk_cd))}
        // get merk
        getMerk($("#kategoribarang_cd").val(),{$result.merk_cd|default:''});
        function getMerk(kategoribarang,merkcd){
	    $.ajax({
                type: 'POST',
                data: 'kategoribarang=' + kategoribarang +'&merk_cd='+ merkcd,
                url: '{$config->site_url("inventarisasi/pengadaan/cari_merk_barang")}',
                success: function(result) {
                    $('#merk_cd').html(result);
                    $('#merk_cd').trigger("change");
                }
            });
	}
        {/if}
        
        $('#kategoribarang_cd').change(function() {
            var kategoribarang = $("#kategoribarang_cd").val();
            // ajax jenis barang
            $.ajax({
                type: 'POST',
                data: 'kategoribarang=' + kategoribarang,
                url: '{$config->site_url("master/barang/cari_jenis_barang")}',
                success: function(result) {
                    $('#jenisbarang_cd').html(result);
                    $('#jenisbarang_cd').trigger("change");
                }
            });
            // ajax merk
            $.ajax({
                type: 'POST',
                data: 'kategoribarang=' + kategoribarang,
                url: '{$config->site_url("master/barang/cari_merk_barang")}',
                success: function(result) {
                    $('#merk_cd').html(result);
                    $('#merk_cd').trigger("change");
                }
            });
        });
        
        $("#barang_harga_beli,#barang_nilai_buku").autoNumeric({
            aSep: '.', aDec: ',', vMax: "999999999999999", vMin: "0"
        });
    });
</script>

<div class="breadcrum">
    <p>
        <a href="{$config->site_url('master/overview')}">Master</a>
        <span></span><a href="{$config->site_url('master/barang')}">Barang</a>
        <span></span><small>Tambah Data</small>
    </p>
    <div class="clear"></div>
</div>  
<div class="sub-content">  
    <div class="navigation">  
        <div class="navigation-button">
            <ul>
                <li><a href="{$config->site_url('master/barang/add')}"><img alt="" src="{$BASEURL}/resource/doc/images/icon/add-icon.png">Tambah Data</a></li>
                <li><a href="{$config->site_url('master/barang')}"><img alt="" src="{$BASEURL}/resource/doc/images/icon/icon.notes.blue.png">Daftar Data</a></li> 
            </ul>
            <div class="clear"></div>
        </div>
    </div> 
    <!-- notification template -->
    {include file="base/templates/notification.html"}
    <!-- end of notification template--> 
    <form action="{$config->site_url('master/barang/add_process')}" method="post">
        <table width="100%" class="table-input">
            <tbody>
                <tr class="headrow">
                    <th colspan="4">Tambah Barang</th>
                </tr>
                <tr>
                    <td width="20%">No Inventaris</td>
                    <td width="30%">
                        <input type="text" maxlength="30" size="30" name="barang_noinventaris" value="{$result.barang_noinventaris|default:''}">
                        <small>* wajib diisi</small>
                    </td>                 
                    <td width="20%">Vendor</td>                   
                    <td width="30%">
                        <select name="vendor_cd" id="vendor_cd" style="width: 200px;">
                            <option value=""></option>
                            {foreach from=$rs_vendor item=data}
                            <option value="{$data.vendor_cd|default:''}" {if {$result.vendor_cd|default:''} eq $data.vendor_cd}selected="selected"{/if}>{$data.vendor_name}</option>
                            {/foreach}
                        </select>
                        <small>* wajib diisi</small>
                    </td>
                </tr>
                <tr>
                    <td>Nama</td>
                    <td>
                        <input type="text" maxlength="100" size="40" value="{$result.barang_nama|default:''}" name="barang_nama">
                        <small>* wajib diisi</small>
                    </td> 
                    <td>Ruang</td>                   
                    <td>
                        <select name="ruang_cd" id="ruang_cd" style="width: 200px;">
                            <option value=""></option>
                            {foreach from=$rs_ruang item=data}
                            <option value="{$data.ruang_cd|default:''}" {if {$result.ruang_cd|default:''} eq $data.ruang_cd}selected="selected"{/if}>{$data.ruang_name}</option>
                            {/foreach}
                        </select>
                        <small>* wajib diisi</small>
                    </td>
                </tr> 
                <tr>
                    <td>Harga</td>
                    <td>
                        <input type="text" style="text-align: right;font-size:16pt;color: red;font-weight: bold;" maxlength="30" size="15" value="{$result.barang_harga_beli|default:''}" name="barang_harga_beli" id="barang_harga_beli">
                        <small>* wajib diisi</small>
                    </td>
                    <td>Group Barang</td>
                    <td>
                        <select name="gpbarang_cd" style="width:200px">
                            <option value=""></option>
                            {foreach from=$rs_gpbarang item=data}
                            <option value="{$data.gpbarang_cd|default:''}" {if {$result.gpbarang_cd|default:''} eq $data.gpbarang_cd}selected="selected"{/if}>{$data.gpbarang_name}</option>
                            {/foreach}
                        </select>
                        <small>* wajib diisi</small>
                    </td> 
                </tr> 
                <tr>   
                    <td>Nilai Buku</td>
                    <td>
                        <input type="text" style="text-align: right;font-size:16pt;color: red;font-weight: bold;" maxlength="30" size="15" value="{$result.barang_nilai_buku|default:''}" name="barang_nilai_buku" id="barang_nilai_buku">
                        <small>* wajib diisi</small>
                    </td> 
                    <td>Lokasi</td>
                    <td>
                    <select name="lokasi_cd" id="lokasi_cd" style="width: 200px;">
                            <option value=""></option>
                            {foreach from=$rs_lokasi item=data}
                            <option value="{$data.lokasi_cd|default:''}" {if {$result.lokasi_cd|default:''} eq $data.lokasi_cd}selected="selected"{/if}>{$data.lokasi_name}</option>
                            {/foreach}
                        </select>
                        <small>* wajib diisi</small>
                    </td>
                </tr> 
                <tr> 
                    <td>Umur Ekonomis</td>
                    <td>
                        <input type="text" maxlength="2" size="5" name="barang_umurekonomis" value="{$result.barang_umurekonomis|default:''}">
                        <small>* wajib diisi</small>
                    </td> 
                    <td>Kategori Barang</td>
                    <td>
                        <select name="kategoribarang_cd" id="kategoribarang_cd" style="width: 200px;">
                            <option value=""></option>
                            {foreach from=$rs_kategoribarang item=data}
                            <option value="{$data.kategoribarang_cd|default:''}" {if {$result.kategoribarang_cd|default:''} eq $data.kategoribarang_cd}selected="selected"{/if}>{$data.kategoribarang_cd|default:''} - {$data.kategoribarang_name}</option>
                            {/foreach}
                        </select>
                        <small>* wajib diisi</small>
                    </td>
                </tr> 
                <tr> 
                    <td>Kondisi</td>
                    <td>
                        <select name="barang_kondisi" id="barang_kondisi" style="width: 200px;">                                                   
                            <option value=""></option>
                            {foreach from=$barang_kondisi item=data}
                            <option value="{$data.data|default:''}" {if {$result.barang_kondisi|default:''} eq $data.data}selected="selected"{/if}>{$data.data}</option>
                            {/foreach}                            
                        </select>
                    </td> 
                    <td>Jenis Barang</td>
                    <td>
                        <select name="jenisbarang_cd" id="jenisbarang_cd" style="width:200px">
                        </select>
                        <small>* wajib diisi</small>
                    </td>               
                </tr>
                <tr>                           
                    <td>Penyusutan</td>
                    <td>
                        <input type="checkbox" name="barang_susut" value="1" {if $result.barang_susut|default:'' eq '1'}checked="checked"{/if}>
                    </td>                       
                    <td>Merk Barang</td>
                    <td>
                        <select name="merk_cd" id="merk_cd" style="width: 200px;">                                                                              
                        </select>
                        <small>* wajib diisi</small>
                    </td>
                </tr>
                <tr>      
                    <td>Tanggal Beli</td>
                    <td>
                        <input class="tanggal" name="barang_tglbeli" type="text" value="{$result.barang_tglbeli|default:''}" size="10" maxlength="10" readonly="readonly" />
                        <small>* wajib diisi</small>
                    </td>                    
                    <td>Status</td>
                    <td>
                        <select name="barang_status" id="barang_status" style="width: 200px;">                                                   
                            <option value=""></option>
                            {foreach from=$barang_status item=data}
                            <option value="{$data.data|default:''}" {if {$result.barang_status|default:''} eq $data.data}selected="selected"{/if}>{$data.data}</option>
                            {/foreach}                            
                        </select>
                    </td>
                </tr>
                <tr>                
                    <td>Keterangan</td>                   
                    <td>
                        <textarea name="barang_keterangan" id="barang_keterangan" cols="50">{$result.barang_keterangan|default:''}</textarea>
                    </td> 
                    <td>Garansi</td>
                    <td>
                        <input type="checkbox" name="barang_garansi" value="1" {if $result.barang_garansi|default:'' eq '1'}checked="checked"{/if}>
                        <input class="tanggal" name="barang_tgl_garansi" type="text" value="{$result.barang_tgl_garansi|default:''}" size="10" maxlength="10" readonly="readonly" />
                        <small>* wajib diisi</small>
                    </td>
                </tr>

                <tr class="submit-box">
                    <td colspan="4">
                        <input type="submit" class="edit-button" value="Simpan" name="save[insert]">
                        <input type="reset" class="edit-button" value="Reset" name="save[reset]">
                    </td>
                </tr>
            </tbody>
        </table>    
    </form> 
</div>